home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d913.lha / AssignPrefs / Source / gadgets.c < prev    next >
C/C++ Source or Header  |  1993-10-03  |  7KB  |  251 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Thomas Frieden
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <pragmas/exec_lib.h>
  24. #include <pragmas/intuition_lib.h>
  25. #include <pragmas/gadtools_lib.h>
  26. #include <pragmas/graphics_lib.h>
  27. #include <pragmas/utility_lib.h>
  28.  
  29. #include "gadgets.h"
  30.  
  31. struct Screen         *Scr = NULL;
  32. UBYTE                 *PubScreenName = NULL;
  33. APTR                   VisualInfo = NULL;
  34. struct Window         *MainWnd = NULL;
  35. struct Gadget         *MainGList = NULL;
  36. struct Menu           *MainMenus = NULL;
  37. UWORD                  MainZoom[4];
  38. struct Gadget         *MainGadgets[8];
  39. UWORD                  MainLeft = 0;
  40. UWORD                  MainTop = 12;
  41. UWORD                  MainWidth = 553;
  42. UWORD                  MainHeight = 206;
  43. UBYTE                 *MainWdt = (UBYTE *)"Assign Preferences V1.02";
  44. struct TextAttr       *Font, Attr;
  45. UWORD                  FontX, FontY;
  46. UWORD                  OffX, OffY;
  47.  
  48. UBYTE *ap_AssType0Labels[] = {
  49.     (UBYTE *)"Locked",
  50.     (UBYTE *)"Path",
  51.     (UBYTE *)"Add",
  52.     (UBYTE *)"Late",
  53.     NULL };
  54.  
  55. struct NewMenu MainNewMenu[] = {
  56.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  57.     NM_ITEM, (STRPTR)"Open", (STRPTR)"O", 0, 0L, NULL,
  58.     NM_ITEM, (STRPTR)"Append", NULL, 0, 0L, NULL,
  59.     NM_ITEM, (STRPTR)"Save As...", (STRPTR)"A", 0, 0L, NULL,
  60.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  61.     NM_ITEM, (STRPTR)"About", (STRPTR)"?", 0, 0L, NULL,
  62.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  63.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
  64.     NM_TITLE, (STRPTR)"Edit", NULL, 0, NULL, NULL,
  65.     NM_ITEM, (STRPTR)"Last Saved", (STRPTR)"L", 0, 0L, NULL,
  66.     NM_TITLE, (STRPTR)"Settings", NULL, 0, NULL, NULL,
  67.     NM_ITEM, (STRPTR)"Save Icons?", (STRPTR)"I", CHECKIT|CHECKED|MENUTOGGLE, 0L, NULL,
  68.     NM_END, NULL, NULL, 0, 0L, NULL };
  69.  
  70. UWORD MainGTypes[] = {
  71.     LISTVIEW_KIND,
  72.     STRING_KIND,
  73.     STRING_KIND,
  74.     CYCLE_KIND,
  75.     BUTTON_KIND,
  76.     BUTTON_KIND,
  77.     BUTTON_KIND,
  78.     BUTTON_KIND
  79. };
  80.  
  81. struct NewGadget MainNGad[] = {
  82.     4, 1, 545, 144, NULL, NULL, GD_ap_List, 0, NULL, NULL,
  83.     102, 159, 153, 17, (UBYTE *)"_Name", NULL, GD_ap_AssName, PLACETEXT_ABOVE, NULL, NULL,
  84.     259, 159, 153, 17, (UBYTE *)"_Path", NULL, GD_ap_Path, PLACETEXT_ABOVE, NULL, NULL,
  85.     416, 159, 133, 17, (UBYTE *)"_Type", NULL, GD_ap_AssType, PLACETEXT_ABOVE, NULL, NULL,
  86.     4, 159, 45, 17, (UBYTE *)"_Add", NULL, GD_ap_Add, PLACETEXT_IN, NULL, NULL,
  87.     53, 159, 45, 17, (UBYTE *)"_Del", NULL, GD_ap_Del, PLACETEXT_IN, NULL, NULL,
  88.     4, 181, 269, 17, (UBYTE *)"_Save", NULL, GD_ap_Save, PLACETEXT_IN, NULL, NULL,
  89.     280, 181, 269, 17, (UBYTE *)"_Quit", NULL, GD_ap_Cancel, PLACETEXT_IN, NULL, NULL
  90. };
  91.  
  92. ULONG *MainGTags[] = {
  93.     (ULONG *)(TAG_DONE),
  94.     (ULONG *)(GTST_MaxChars), (ULONG *)256, (ULONG *)(STRINGA_Justification), (ULONG *)(GACT_STRINGCENTER), (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE),
  95.     (ULONG *)(GTST_MaxChars), (ULONG *)256, (ULONG *)(STRINGA_Justification), (ULONG *)(GACT_STRINGCENTER), (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE),
  96.     (ULONG * )(GTCY_Labels), (ULONG *)&ap_AssType0Labels[ 0 ], (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE),
  97.     (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE),
  98.     (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE),
  99.     (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE),
  100.     (ULONG *)(GT_Underscore), (ULONG *)'_', (ULONG *)(TAG_DONE)
  101. };
  102.  
  103. static UWORD ComputeX( UWORD value )
  104. {
  105.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  106. }
  107.  
  108. static UWORD ComputeY( UWORD value )
  109. {
  110.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  111. }
  112.  
  113. static void ComputeFont( UWORD width, UWORD height )
  114. {
  115.     Font = &Attr;
  116.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  117.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  118.     FontX = Scr->RastPort.Font->tf_XSize;
  119.  
  120.     OffX = Scr->WBorLeft;
  121.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  122.  
  123.     if ( width && height ) {
  124.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  125.             goto UseTopaz;
  126.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  127.             goto UseTopaz;
  128.     }
  129.     return;
  130.  
  131. UseTopaz:
  132.     Font->ta_Name = (STRPTR)"topaz.font";
  133.     FontX = FontY = Font->ta_YSize = 8;
  134. }
  135.  
  136. int SetupScreen( void )
  137. {
  138.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  139.         return( 1L );
  140.  
  141.     ComputeFont( 0, 0 );
  142.  
  143.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  144.         return( 2L );
  145.  
  146.     return( 0L );
  147. }
  148.  
  149. void CloseDownScreen( void )
  150. {
  151.     if ( VisualInfo ) {
  152.         FreeVisualInfo( VisualInfo );
  153.         VisualInfo = NULL;
  154.     }
  155.  
  156.     if ( Scr        ) {
  157.         UnlockPubScreen( NULL, Scr );
  158.         Scr = NULL;
  159.     }
  160. }
  161.  
  162. int OpenMainWindow( void )
  163. {
  164.     struct NewGadget    ng;
  165.     struct Gadget    *g;
  166.     UWORD        lc, tc;
  167.     UWORD        wleft = MainLeft, wtop = MainTop, ww, wh;
  168.  
  169.     ComputeFont( MainWidth, MainHeight );
  170.  
  171.     ww = ComputeX( MainWidth );
  172.     wh = ComputeY( MainHeight );
  173.  
  174.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  175.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  176.  
  177.     if ( ! ( g = CreateContext( &MainGList )))
  178.         return( 1L );
  179.  
  180.     for( lc = 0, tc = 0; lc < Main_CNT; lc++ ) {
  181.  
  182.         CopyMem((char * )&MainNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  183.  
  184.         ng.ng_VisualInfo = VisualInfo;
  185.         ng.ng_TextAttr   = Font;
  186.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  187.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  188.         ng.ng_Width      = ComputeX( ng.ng_Width );
  189.         ng.ng_Height     = ComputeY( ng.ng_Height);
  190.  
  191.         MainGadgets[ lc ] = g = CreateGadgetA((ULONG)MainGTypes[ lc ], g, &ng, ( struct TagItem * )&MainGTags[ tc ] );
  192.  
  193.         while( MainGTags[ tc ] ) tc += 2;
  194.         tc++;
  195.  
  196.         if ( NOT g )
  197.             return( 2L );
  198.     }
  199.  
  200.     if ( ! ( MainMenus = CreateMenus( MainNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  201.         return( 3L );
  202.  
  203.     LayoutMenus( MainMenus, VisualInfo, TAG_DONE );
  204.  
  205.         MainZoom[0] = MainZoom[1] = 0;
  206.     if ( MainWdt )
  207.         MainZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)MainWdt, strlen((char *)MainWdt )) + 80;
  208.     else
  209.         MainZoom[2]  = 80L;
  210.         MainZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  211.  
  212.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  213.                 WA_Left,    wleft,
  214.                 WA_Top,        wtop,
  215.                 WA_Width,    ww + OffX + Scr->WBorRight,
  216.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  217.                 WA_IDCMP,    LISTVIEWIDCMP|STRINGIDCMP|CYCLEIDCMP|BUTTONIDCMP|IDCMP_SIZEVERIFY|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  218.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  219.                 WA_Gadgets,    MainGList,
  220.                 WA_Title,    MainWdt,
  221.                 WA_ScreenTitle,    "Assign Preferences V1.02 © 1993 DIgital DImensions. Written by Thomas Frieden",
  222.                 WA_PubScreen,    Scr,
  223.                 WA_Zoom,    MainZoom,
  224.                 TAG_DONE )))
  225.     return( 4L );
  226.  
  227.     SetMenuStrip( MainWnd, MainMenus );
  228.     GT_RefreshWindow( MainWnd, NULL );
  229.  
  230.     return( 0L );
  231. }
  232.  
  233. void CloseMainWindow( void )
  234. {
  235.     if ( MainMenus      ) {
  236.         ClearMenuStrip( MainWnd );
  237.         FreeMenus( MainMenus );
  238.         MainMenus = NULL;    }
  239.  
  240.     if ( MainWnd        ) {
  241.         CloseWindow( MainWnd );
  242.         MainWnd = NULL;
  243.     }
  244.  
  245.     if ( MainGList      ) {
  246.         FreeGadgets( MainGList );
  247.         MainGList = NULL;
  248.     }
  249. }
  250.  
  251.